//index.js
Page({
  data: {
    teams: [],
    hasMore: true,
    showLoading: true,
    hidden: false,
    hasRefesh: false,
    userInfo: {},
    tabBar: {
      "color": "#878787",
      "selectedColor": "#000",
      "borderStyle": "black",
      "backgroundColor": "#fcfcfc",
      "list": [
        {
          "pagePath": "../team_index/index",
          "iconPath": "../../static/imgs/tabBar/index.png",
          "selectedIconPath": "../../static/imgs/tabBar/index-on.png",
          "text": "首页",
          active: true
        },
        {
          "pagePath": "../team_post/post",
          "iconPath": "../../static/imgs/tabBar/add.png",
          "selectedIconPath": "../../static/imgs/tabBar/add-on.png",
          "text": "发布"
        },
        {
          "pagePath": "../team_self/self",
          "iconPath": "../../static/imgs/tabBar/account.png",
          "selectedIconPath": "../../static/imgs/tabBar/account-on.png",
          "text": "我的"
        }
      ],
      "position": "bottom"
    }
  },
  //事件处理函数
  bindViewTap: function (e) {
    var ds = e.currentTarget.dataset;
    console.log(ds);
    wx.navigateTo({
      url: '../team_detail/detail?title=' + ds.title + '&name=' + ds.name + '&st=' + ds.starttime + '&et=' + ds.endtime + '&c=' + ds.content + '&rc=' + ds.rcontent + '&cw=' + ds.cw + '&cv=' + ds.cv,
    })
  },
  onLoad: function () {
    // var that = this
    // console.log(that.data)
    // //获取缓存中的userid
    // var userid = wx.getStorageSync('userid') || 0;
    // wx.setStorageSync('userid', userid);
    // //存入全局数据
    // getApp().globalData.userid = wx.getStorageSync('userid');
    // console.log(getApp().globalData.userid);
  },
  onShow: function () {
    var that = this;
    //console.log(getApp().globalData.my_server+'/team/message');
    wx.request({
      url: getApp().globalData.my_server +'/team/message',
      method: 'POST',
      headr: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res)
        that.setData({
          teams: res.data,
          hidden: true,
          hasRefesh: false
        });
      },
      fail: function () {
        wx.showToast({
          title: '获取数据失败，请稍后重试！',
          icon: 'false',
          duration: 1000
        })
      },
    });
  },
  //加载更多
  loadMore: function (e) {
    var that = this;
    that.setData({
      hasRefesh: true,
    });
    if (!this.data.hasMore) return
    this.onShow()
    setTimeout(() => {
      wx.stopPullDownRefresh()//表示停止刷新
    }, 1000)
  },
  //刷新处理
  refesh: function (e) {
    var that = this;
    that.setData({
      hasRefesh: true
    });
    this.onShow()
    setTimeout(() => {
      wx.stopPullDownRefresh()//表示停止刷新
    }, 1000)
  }
})
